﻿using System;
using System.Linq;
using mal.WP7.GoogleAnalytics.Business.Repository;
using mal.WP7.GoogleAnalytics.Business.Resources;
//using mal.WP7.GoogleAnalytics.Business.Resources;

namespace mal.WP7.GoogleAnalytics.ViewModels.Dashboard
{
    public class DashboardItemYear : DashboardItemBase
    {
        #region Fields

        #endregion

        #region Construction / Destruction
        public DashboardItemYear()
        {
            this.Label = ResourceText.Year;
        }
        #endregion

        #region enum, struct, class

        #endregion

        #region Properties

        #endregion

        #region Methods
        protected override void LoadDatas(Website website)
        {
            if (website.DashboardYear != null && this.Rows != null)
            {
                IsLoading = false;
                DashboardRowViewModel row = this.Rows.First(w => w.WebsiteId == website.Id);

                row.CurrentValue = website.DashboardYear[website.DashboardYear.Count - 1].Value;
                row.PreviousValue = website.DashboardYear[website.DashboardYear.Count - 2].Value;

                row.PreviousValue = row.PreviousValue * (double)(DateTime.Now.DayOfYear) / 365.0;
            }
            else
            {
                IsLoading = true;
            }
        }

        protected override WebsiteStatisticsAvailableMessage.WebsiteStatisticsAvailableType GetWebsiteStatisticsAvailableType()
        {
            return WebsiteStatisticsAvailableMessage.WebsiteStatisticsAvailableType.DashboardYear;
        }

        #endregion

        #region Events

        #endregion
    }
}
